package java学习.leetcode.editor.cn;
/**
 * @author 刘世锦
 * 2022-10-15 13:49:27	 当前时间
 */
//请实现一个函数，把字符串 s 中的每个空格替换成"%20"。 
//
// 
//
// 示例 1： 
//
// 输入：s = "We are happy."
//输出："We%20are%20happy." 
//
// 
//
// 限制： 
//
// 0 <= s 的长度 <= 10000 
// Related Topics 字符串 
// 👍 357 👎 0

public class 替换空格{
	public static void main(String[] args) {
		Solution solution = new 替换空格().new Solution();
		
	}
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
	public String replaceSpace(String s) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i)==' '){
				sb.append('%');sb.append('2');sb.append('0');
			}else{
				sb.append(s.charAt(i));
			}
		}
		return sb.toString();



	}

		public String replaceSpacee(String s) {
		String res = "";
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i)==' '){
				res += '%';
				res += '2';
				res += '0';

			}else {
				res+=s.charAt(i);
			}
		}
		return res;
	}
    public String replaceSpace1(String s) {
		String replace = s.replace(" ", "%20");
		return replace;
	}
}
//leetcode submit region end(Prohibit modification and deletion)

}
